<?php

class RetailModel extends Model{
		
	public function get_province_list(){
		$sql	=	"select a1.*,IFNULL(a2.retail_amount,0) retail_amount from ybr_region a1 
    				left join (
    					select count(*) retail_amount,province from ybr_retail group by province
    				) a2 on a2.province = a1.region_id
    				where a1.region_type = 1
    				";		
		return $this->query($sql);
	}
	
	public function get_city_list($parent_id = null,$region_type = 2){
		if(empty($parent_id)){
			return array();
		}
		$sql	=	"select a1.*,IFNULL(a2.retail_amount,0) retail_amount from ybr_region a1 
    				left join (
    					select count(*) retail_amount,province,city from ybr_retail where province = '{$parent_id}' group by city
    				) a2 on a2.city = a1.region_id
    				where a1.region_type = 2 and a1.parent_id = '{$parent_id}'
    				";		
		return $this->query($sql);	
	}
	
	
	
}























